/**
 * Copyright (c) 2019, NewStrength. All rights reserved.
 * 2019-01-26 16:24:37
 */
package cn.newstrength.shihaipeng.step;

import cn.newstrength.shihaipeng.data.SHPSampleObj;
import cn.newstrength.shihaipeng.service.SHPSampleService;
import cn.newstrength.wtdf.plugin.param.TranParams;
import cn.newstrength.wtdf.plugin.result.TranResult;
//import cn.newstrength.wtdf.plugin.util.StepUtils;
import cn.newstrength.wtdf.web.databus.DataContext;
import cn.newstrength.wtdf.web.processor.Operation;
import cn.newstrength.wtdf.web.processor.OperationStep;
import cn.newstrength.wtdf.web.util.StepUtils;
import cn.newstrength.zhangtairan.data.ZTRSampleObj;
import cn.newstrength.zhangtairan.service.ZTRSampleService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;

/**
 * 事务类型的数据库操作演示
 * @author Xd
 *
 */
public class SHPInsertSampleByTransactionalStep2 implements OperationStep {
	
	private static final Logger logger = LoggerFactory.getLogger(SHPInsertSampleByTransactionalStep2.class);
	
	@Override
	public int excute(Operation oper) {
		/*
		 * 数据总线
		 */
		DataContext ctx = oper.getContext();
		/*
		 * 装载参数
		 */
		SHPSampleObj sampleObj = StepUtils.requestToBean(oper,"mapSet", SHPSampleObj.class);
		//sampleObj.setName(null);//将name属性修改为 null 验证Operation级别的事务
		TranParams<SHPSampleObj> params = new TranParams<>(sampleObj);
		params.setResource(ctx.getResource());//Mybatis mapper 配置
		params.setSummary("数据写入");
		logger.info("参数装载完成");
		/*
		 * 获取服务
		 */
		SHPSampleService sampleService = oper.getBean("sampleService", SHPSampleService.class);
		TranResult<SHPSampleObj> tranResult = sampleService.insert(params);
		/*
		 * 将结果放置到数据总线上，供其他服务调用
		 */
		//ctx.setTranResult(tranResult);
		oper.setTranResult(tranResult);
		return 0;
	}

	@Override
	public int init(Map<String, String> input) {
		return 0;
	}

}
